package com.ctg.behavior.calc.impala.builder.userlist;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.ctg.behavior.common.consts.CtCalcConsts;
import com.ctg.behavior.common.funnel.CtFunnelSliceBody;
import com.ctg.behavior.common.userslist.CtULCalcBody;
import com.ctg.behavior.common.userslist.upper.CtUpperFunnelBody;

@Component
public class CtFunnelExtCalcBodyBuilder {

	public CtFunnelSliceBody doBuilder(CtULCalcBody ulCalcBody) {

		CtFunnelSliceBody funnelExtCalcBody = new CtFunnelSliceBody();

		CtUpperFunnelBody upperFunnelBody = null;
		upperFunnelBody = JSON.parseObject(ulCalcBody.getUpperTaskData(), CtUpperFunnelBody.class);

		// 把CtUpperFunnelBody转为CtFunnelExtCalcBody
		funnelExtCalcBody.setAppId(ulCalcBody.getAppId());
		funnelExtCalcBody.setRequestId(ulCalcBody.getRequestId());
		funnelExtCalcBody.setBookmarkId(ulCalcBody.getBookmarkId());

		funnelExtCalcBody.setFromDate(upperFunnelBody.getFromDate());
		funnelExtCalcBody.setToDate(upperFunnelBody.getToDate());
		funnelExtCalcBody.setUnit(CtCalcConsts.UNIT_TYPE_DAY);
		funnelExtCalcBody.setFilter(upperFunnelBody.getFilter());
		funnelExtCalcBody.setSubTaskType(ulCalcBody.getUpperTaskType());
		funnelExtCalcBody.setSubjectId(CtCalcConsts.SUBJECT_USER_ID);

		funnelExtCalcBody.setFunnelId(Long.valueOf(upperFunnelBody.getFunnelId()));
		funnelExtCalcBody.setFunnelDetail(upperFunnelBody.getFunnelBody());
		// funnelCalcBody.setByFieldSteps(upperFunnelBody.getByFieldSteps());
		funnelExtCalcBody.setByFields(upperFunnelBody.getByFields());
		
		//slice系列
		funnelExtCalcBody.setSliceStep(upperFunnelBody.getSliceStep());
		funnelExtCalcBody.setSliceByValues(upperFunnelBody.getSliceByValues());
		
		return funnelExtCalcBody;

	}

}
